#coding=utf-8
from uliweb import expose
import generic.views as g_views

get_kfzx_url = g_views.get_url('/config/kfzx')
layout = 'config_kfzx_layout.html'

def __begin__():
    from uliweb import function
    return function('require_login')()
    
@expose('/config/kfzx/list')
def config_kfzx_list():
    return g_views.generic_list('kfzx', get_url=get_kfzx_url, layout=layout, add_button_text='增加开发中心')

@expose('/config/kfzx/add')
def config_kfzx_add():
    return g_views.generic_add('kfzx', get_url=get_kfzx_url, layout=layout, title='增加开发中心')

@expose('/config/kfzx/edit/<int:id>')
def config_kfzx_edit(id):
    if request.user.is_superuser:
        return g_views.generic_edit('kfzx', id, get_url=get_kfzx_url, layout=layout, title='修改开发中心')
    else:
        flash('你不是超级用户或管理员，无法编辑此开发中心！')
        return redirect(url_for(config_kfzx_list))

@expose('/config/kfzx/delete/<int:id>')
def config_kfzx_delete(id):
    if request.user.is_superuser:
        return g_views.generic_delete('kfzx', id, get_url=get_kfzx_url)
    else:
        flash('你不是超级用户或管理员，无法删除此开发中心！')
        return redirect(url_for(config_kfzx_list))

@expose('/config/kfzx/view/<int:id>')
def config_kfzx_view(id):
    from uliweb.utils.generic import DetailView
    import uliweb.orm as orm
    from uliweb.utils.textconvert import text2html
    
    Kfzx = orm.get_model('kfzx')
    condition = (Kfzx.c.id == int(id))

    view = DetailView('kfzx', condition=condition)
    view.fields_convert_map = {'reason':text2html}
    return view.run()

